package com.guigu.controller;

import com.guigu.pojo.Order;
import com.guigu.pojo.Ordersetting;
import com.guigu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


@RestController
public class OrderController {
    @Autowired
    OrderService service;

    @PostMapping("/insert")
    public int add(@RequestBody Order order){
        String date=order.getOrderdate().substring(0,8);
        Integer day=Integer.parseInt(order.getOrderdate().substring(8,10))+1;
        order.setOrderdate(date+day.toString());
        return service.insert(order);
    }

    @GetMapping("LzNorderSetting")
    public Ordersetting LzNorderSetting(String date)throws Exception{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = simpleDateFormat.parse(date);
        Calendar calendar = Calendar.getInstance();
        long d =  date1.getTime()+1*24*3600*1000;
        calendar.setTimeInMillis(d);
        return service.yyorderSetting(simpleDateFormat.format(calendar.getTime()));
    }



}
